package com.segment.ranking.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.segment.mybatis.SqlSessionFactoryManager;
import com.segment.ranking.vo.RankingVO;

public class RankingDAO {
	SqlSessionFactory sqlSessionFactory = SqlSessionFactoryManager.getSqlMapper();
	
	public List<RankingVO> test(RankingVO vo){
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			List<RankingVO> list = session.selectList("segment.getScore", vo);
			return list;
		}finally{
			session.close();
		}
	}
	
	public List<RankingVO> getRanking(String userCode){
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			List<RankingVO> list = session.selectList("segment.ranking", userCode);
			return list;
		}finally{
			session.close();
		}
	}

	public List<RankingVO> getNewUserCode(){
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			List<RankingVO> list = session.selectList("segment.getNewUserCode");
			return list;
		}finally{
			session.close();
		}
	}
	
	public void insertUserCode(RankingVO vo){
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			int rtn = session.insert("segment.insertUserCode", vo);
		}finally{
			session.close();
		}
	}
	
	public List<RankingVO> checkUser(String userCode){
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			List<RankingVO> list = session.selectList("segment.checkUser", userCode);
			return list;
		}finally{
			session.close();
		}
	}
	
	public void updateFilnalAccessDate(String userCode){
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			int rtn = session.insert("segment.updateFilnalAccessDate", userCode);
		}finally{
			session.close();
		}
	}
	
	public List<RankingVO> getScore(RankingVO vo){
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			List<RankingVO> list = session.selectList("segment.getScore", vo);
			return list;
		}finally{
			session.close();
		}
	}
	
	public void insertScore(RankingVO vo){
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			int rtn = session.insert("segment.insertScore", vo);
		}finally{
			session.close();
		}
	}
	
	public void updateScore(RankingVO vo){
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			int rtn = session.insert("segment.updateScore", vo);
		}finally{
			session.close();
		}
	}
	
}
